Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
[Vue warn]: Error in v-on handler: "TypeError: Cannot read property 'Array' of undefined"

I want to check the inputs for emptiness when clicking on the button I filter the array if one of the inputs is empty I try to add an error to the array, but when I click on the button I get the error "'ErrorList' of undefined" I think that the error is that I trying to get an array called ErrorList inside a method called save, but how do I get rid of this problem then? You can also look at my code in codesandbox

<template>
  <div>
    <form>
      <div v-for="(learning, i) in general.learnings" :key="i">
        <input type="text" v-model="general.learnings[i]" maxlength="120" />
      </div>

      <button @click="save">Save</button>
    </form>
  </div>
</template>

<script>
export default {
  methods: {
    save(e) {
      e.preventDefault();

      this.general.learnings.filter(function (el) {
        if (el !== "") {
          return true;
        } else {
          this.errorList.push("Error");
        }
      });
    },
  },
  data() {
    return {
      errorList: [],
      general: {
        learnings: ["", ""],
      },
    };
  },
};
</script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

this is happening because reference of this is not referencing to your component inside the filter.

Simply change to arrow function to fix the issue.

 this.general.learnings.filter( (el) => {
        if (el !== "") {
          return true;
        } else {
          this.errorList.push("Error");
        }
      });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!